//
//  ViewController.m
//  18_SQLite
//
//  Created by 徐昊 on 16/8/8.
//  Copyright © 2016年 徐昊. All rights reserved.
//

#import "ViewController.h"
#import "SQLiteDataBaseManager.h"
#import "Student.h"
@interface ViewController ()
@property (nonnull, strong) SQLiteDataBaseManager *dataBaseMangger;
@end

@implementation ViewController
- (IBAction)openSQLite:(id)sender {
    _dataBaseMangger = [SQLiteDataBaseManager sharedManager];
    // SQLite3
    // 注意: 使用SQLite需要引入libsqlite3.0.tbd
    // libsqlite3.0.tbd 和 libsqlite3.tbd区别
    // libsqlite3.0.tbd 是libsqlite3.tbd的替身文件, 防止用户误删
    [_dataBaseMangger openSQLite3];
}
- (IBAction)closeSQLite:(id)sender {
    [_dataBaseMangger closeSQLite3];
}
- (IBAction)createSQLite:(id)sender {
    [_dataBaseMangger createTable];
}
- (IBAction)insertStu:(id)sender {
    Student *stu = [[Student alloc] init];
    stu.stu_id = 38;
    stu.stu_name = @"XX";
    [_dataBaseMangger insertStu:stu];
}
- (IBAction)deleteStu:(id)sender {
//    Student *stu = [[Student alloc] init];
//    stu.stu_id = 38;
//    stu.stu_name = @"XX";
//    [_dataBaseMangger deleteStu:stu];
    [_dataBaseMangger deleteAll];
}
- (IBAction)updateName:(id)sender {
    [_dataBaseMangger updateOldName:@"XX" newName:@"王道林"];
}
- (IBAction)selectAll:(id)sender {
    NSArray *array = [_dataBaseMangger selectAll];
    NSLog(@"%ld", array.count);
    NSLog(@"%@", array);
}


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
